<?php


namespace app\index\controller;


use app\BaseController;
use app\index\business\messageBus;
use app\index\validate\messageValidate;
use think\exception\ValidateException;
use think\facade\View;

class Message extends BaseController
{
    public function index(){
        View::assign('title','客户留言');
        return View::fetch();
    }
    public function addMessage(){
        $mobile = $this->request->param('mobile');
        $name = $this->request->param('name');
        $content = $this->request->param('content');
        $data = [
            'mobile'=>$mobile,
            'name'=>$name,
            'content'=>$content,
        ];
//        dump($data);exit();
        try {
            validate(messageValidate::class)->scene('add_message')->check($data);
        }catch (ValidateException $e){
            return show(config('status.error'),$e->getError());
        }

        $messageBus = new messageBus();
        try {
           $res = $messageBus->addMessageBus($data);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'留言成功',$res);
    }
}